package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.daos.AdminOrderMapper;
import com.project.entity.Order1;
import com.project.entity.RestPOJO;
import com.project.service.AdminOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags="管理员订单管理接口")//tags:说明信息
public class AdminOrderController {

    @Autowired
    private AdminOrderService adminOrderService;

    @ApiOperation(
            value = "查询所有租户信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="keyWord",value="条件搜索关键字",required=true),
            @ApiImplicitParam(paramType="query",name="currentPage",value="当前页",required=true),
            @ApiImplicitParam(paramType="query",name="pageSize",value="每页显示的条目数",required=true)
    })

    @RequestMapping("/selAllOrder")
    public RestPOJO selAllOrder(String keyWord,Integer currentPage,Integer pageSize){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Order1> allOrder = adminOrderService.selAllOrder(keyWord,currentPage, pageSize);
        if(allOrder != null && allOrder.getList().size() > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("查询成功");
            restPOJO.setData(allOrder);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("查询失败");
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "异常订单处理",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @RequestMapping("/delOrder")
    public RestPOJO delOrder(@RequestBody Object[] ids){
        RestPOJO restPOJO = new RestPOJO();
        Integer delCount = adminOrderService.delOrder(ids);
        if(delCount > 0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("删除成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("删除失败");
        }
        return restPOJO;
    }
}
